$(function () {
    init_form();
});
/**
 * 初始化验证和树状图
 * **/
function init_form() {
    //初始化菜单栏的数据
    $.post(ctx + "collage/getAllCollage", {}, function (r) {
        if (r.code === 0) {
            var data = r.msg;
            $('#collageTree').jstree({
                "core": {
                    'data': data.children,
                    'multiple': false
                },
                "state": {
                    "disabled": true
                },
                "checkbox": {
                    "three_state": false
                },
                "plugins": ["wholerow", "checkbox"]
            });
        } else {
            $JuXue.n_danger(r.msg);
        }
    });
}
/**
 * 保存信息
 * **/
function saveCollageInfo(){
    var ref = $('#collageTree').jstree(true);
    var arrayList = ref.get_checked();
    if(arrayList.length<=0){
        $("[name='parentId']").val(0);
    }else{
        $("[name='parentId']").val(ref.get_checked()[0]);
    }
    var form_data = $("#collage-add-form").serialize();

    $.post(ctx + "collage/addCollage", form_data, function (r) {
        if (r.code === 0) {
            $JuXue.n_success(r.msg);
            $("#sale-modal").modal("hide");
            CollageRefresh();
        } else $JuXue.n_danger(r.msg);
    });

}
